%define KernelSize			30				;30 sectors
%define Kernelplace			0x100000

[BITS 16]
[ORG 0x1000]


	jmp _boot2


;;;;;;;;;; GSDB ;;;;;;;;;;;;;;;;;;;;;;;;;;
				          ;;
bootdrv 			db 0      ;;
cursorX 			db 0      ;;
cursorY 			db 0      ;;
text_attr 			db 0x0f   ;;
                         		   ;;
RAMsize 			dd 0      ;;
                         			;;
sectorsPerTrack 	db 0     		;;
headsPerCyllinder 	db 0			;;
						 			;;
;;;;;;;;;; 0x1002 ;;;;;;;;;;;;;;;;;;;;


_boot2:	
	
    mov [bootdrv], dl
	
    mov ah, 0x0E
    mov bx, 0x07
    mov al, '.'
    int 0x10

	
load:
    mov ah, 0               ; On reset le lecteur
    int 13h

    mov ax, 0
    mov es, ax
    mov bx, 0x8000 

    mov ah, 2
    mov al, 2
    mov ch, 0
    mov cl, 12
    mov dh, 0
    mov dl, [bootdrv] ; On tire le second bootloader de l'unite de boot
    int 0x13
    jc load

	
	lgdt [gdt_desc]

	mov ebx, cr0
	or bl, 1
	mov cr0, ebx

	jmp 08h:pmode

	



[BITS 32]

pmode:
	
	mov ax, 10h             ; save data segment
    mov ds, ax              ; setup data segment
    mov ss, ax              ; setup stack segment
    mov esp, 0900000h        ; move the stack pointer to 090000h
	
	mov bl, [bootdrv]
	xor edx, edx
	mov edx, 0x7FFF
	mov [edx], bl
	
	xor edx, edx
	mov edx, 0x7000
	
	xor eax, eax
	mov eax, Kernelplace
	mov [edx], eax
	
	add edx, 4
	
	xor eax, eax
	mov eax, KernelSize
	mov [edx], eax
	
	add edx, 4
	
	xor eax, eax
	mov eax, [bootdrv]
	mov [edx], eax
	
	call 08h:0x8000			; Call the disk driver !
	
	jmp 08h:Kernelplace

	



gdt:                    ; address for the GDT

gdt_null:               ; null Segment
        dd 0
        dd 0

gdt_code:               ; code segment, read/execute, nonconforming
        dw 0FFFFh
        dw 0
        db 0
        db 10011010b
        db 11001111b
        db 0

gdt_data:               ; data segment, read/write, expand down
        dw 0FFFFh
        dw 0
        db 0
        db 10010010b
        db 11001111b
        db 0

gdt_end: 

gdt_desc: 
        dw gdt_end - gdt - 1    ; limit (size)
        dd gdt                  ; address of the GDT



times 5120 - ($$ - $) db 0
